package com.system.couponserver.controller;

import com.system.couponserver.pojo.User;
import com.system.couponserver.pojo.User_Coupon;
import com.system.couponserver.service.UserCouponService;
import com.system.couponserver.utils.Constant;
import com.system.couponserver.utils.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "优惠卷管理每一组",tags = "优惠卷管理每一组")
@RequestMapping(value = "urcp")
public class UserCouponController {

    @Autowired
    private UserCouponService userCouponService;
    /**
     * 查询所有
     */
    @RequestMapping(value = "/query01.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "优惠卷查询接口",notes = "查询优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query01(@RequestBody User user){
        System.out.println(user.getCurrentPsge());
        System.out.println(user.getPageSize());
        ResultData resultData = userCouponService.query01(user.getCurrentPsge(),user.getPageSize());
        return resultData;
    }

    /**
     * 条件查询 通过优惠卷id 优惠卷状态 查询
     */
    @RequestMapping(value = "/query02.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "通过优惠卷id 优惠卷状态查询接口",notes = "通过优惠卷id 优惠卷状态查询优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query02(@RequestBody User user){
        System.out.println(user.getCurrentPsge());
        System.out.println(user.getPageSize());
        ResultData resultData = userCouponService.query03(user);
        return resultData;
    }

    /**
     * 用户领取优惠卷
     */
    @RequestMapping(value = "/insert01.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "领取优惠卷 需传入用户id 和 优惠卷id 接口",notes = "领取优惠卷 需传入用户id 和 优惠卷id ",httpMethod = "post", response = ResultData.class)
    public ResultData insert01(@RequestBody User_Coupon user_coupon){
        ResultData resultData = new ResultData();
        int result = userCouponService.insert(user_coupon);
        if(result > 0 ){
            resultData.setCode(Constant.CODE_STATUS_SUCCESS);
            resultData.setMessage("领取成功");
        } else {
            resultData.setCode(Constant.CODE_STATUS_FAILURE);
            resultData.setMessage("领取失败");
        }
        return resultData;
    }
}
